package com.flyme.module.base.provider.service.impl;

import cn.hutool.core.date.DateUtil;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.base.client.entity.SysCreditbank;
import com.flyme.module.base.provider.mapper.SysCreditbankMapper;
import com.flyme.module.base.provider.service.SysCreditbankService;
import org.springframework.stereotype.Service;


@Service
public class SysCreditbankServiceImpl extends BaseServiceImpl<SysCreditbankMapper, SysCreditbank> implements SysCreditbankService {

    /**
     * 根据用户查询学分
     */
    public EntityMap findByUser(Long userId){
        CriteriaQuery queryWrapper = new CriteriaQuery<EntityMap>(new PagerInfo());
        queryWrapper.select("cb.*,u.email,u.userName,u.sex,u.mobile,u.birthday,u.address,u.company,u.deptName,u.positionName,u.qq");
        queryWrapper.eq("cb.userId", userId);
        queryWrapper.createAlias("user", "u");
        PqGrid pqGrid = pageList(queryWrapper);
        if(pqGrid.getRows().size()>0){
            return (EntityMap) pqGrid.getRows().get(0);
        }
        return new EntityMap();
    }

    /**
     * 根据用户获取记录
     */
    public SysCreditbank getByUser(Long userId){
        return getOne(q().eq(true, "userId", userId), false);
    }

    public Integer countByUser(Long userId){
        return count(q().eq(true, "userId", userId));
    }
}
